package com.yunji.system.convert;

import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.domain.MemberDO;
import com.yunji.common.model.domain.StaffDO;
import com.yunji.common.model.domain.SysUserDO;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.model.enums.LoginTypeEnum;
import com.yunji.system.context.SysCommonService;

/**
 * @author : peter-zhu
 * @date : 2024/12/30 15:18
 * @description : TODO
 **/
public class LoginInfoConvert {

    public static LoginInfo convertLoginInfo(SysUserDO userDO) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginType(LoginTypeEnum.SYSTEM);

        loginInfo.setUserId(userDO.getUserId());
        loginInfo.setUsername(userDO.getUserName());
        loginInfo.setPassword(userDO.getPassword());

        loginInfo.setNickname(userDO.getNickName());
        loginInfo.setRealName(userDO.getNickName());

        loginInfo.setBelongId(userDO.getBelongId());
        loginInfo.setBelongName(SysCommonService.getBelongName(userDO.getBelongId()));
        loginInfo.setAgentId(userDO.getAgentId());
        loginInfo.setDeptId(userDO.getDeptId());

        loginInfo.setPhone(userDO.getPhonenumber());
        loginInfo.setUserType(userDO.getUserType());

        loginInfo.setCreateTime(userDO.getCreateTime());

        loginInfo.setRoles(SysCommonService.getRoleListByUserId(userDO.getUserId()));
        return loginInfo;
    }

    public static LoginInfo convertLoginInfo(StaffDO staff) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginType(LoginTypeEnum.STAFF);

        loginInfo.setUserId(staff.getId());
        loginInfo.setUsername(staff.getStaffId());
        loginInfo.setPassword(staff.getStaffPwd());

        loginInfo.setNickname(staff.getStaffName());
        loginInfo.setRealName(staff.getStaffName());

        loginInfo.setBelongId(staff.getBelongId());
        loginInfo.setBelongName(SysCommonService.getBelongName(staff.getBelongId()));
        loginInfo.setAgentId(staff.getAgentId());
        //loginInfo.setDeptId(staff.getDeptId());
        loginInfo.setSiteId(staff.getManagerId());

        loginInfo.setPhone(staff.getStaffTel());
        loginInfo.setUserType(UserType.STAFF.getCode());

        loginInfo.setCreateTime(staff.getCreateTime());
        return loginInfo;
    }


    public static LoginInfo convertLoginInfo(MemberDO member) {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setLoginType(LoginTypeEnum.CUSTOMER);
        loginInfo.setOpenId(member.getOpenid());
        loginInfo.setUserId(member.getId());
        loginInfo.setUsername(member.getPhone());

        loginInfo.setNickname(member.getName());
        loginInfo.setRealName(member.getName());

        loginInfo.setPhone(member.getPhone());
        loginInfo.setUserType(UserType.USER.getCode());

        loginInfo.setCreateTime(member.getCreateTime());
        return loginInfo;
    }

}
